In-Class work
1) Show a map outline of Iowa and Illinois (similar to Minnesota map upstream)
# Grab both Iowa and Illinois state codes
iowa_illinois <- states %>%
filter(name %in% c("Iowa","Illinois")) %>%
st_transform(2163)
# Isolate lakes from Iowa and Illinois
iowa_illinois_lakes <- spatial_lakes[iowa_illinois,]
# Display the Outline
mapview(iowa_illinois, col.regions = "chartreuse4")
2) Subset LAGOS data to these sites, how many sites are in Illinois and Iowa combined? How does this compare to Minnesota?
# Give an output statement on the sites in Iowa + Illinois vs. Minnesota
print(paste("There are", nrow(iowa_illinois_lakes), "lakes in Iowa and Illinois, and", nrow(minnesota_lakes), "lakes in Minnesota."))
## [1] "There are 16466 lakes in Iowa and Illinois, and 29038 lakes in Minnesota."
3) What is the distribution of lake size in Iowa vs. Minnesota?
- Here I want to see a histogram plot with lake size on x-axis and frequency on y axis (check out geom_histogram)
# Isolate Iowa lakes and mutate state name
iowa <- iowa_illinois %>% filter(name == "Iowa")
iowa_lakes <- spatial_lakes[iowa,] %>%
mutate(name = "Iowa")
iowa_minnesota_lakes <- rbind(iowa_lakes, minnesota_lakes)
# p1 <- ggplot(iowa_lakes, aes(lake_area_ha)) +
# geom_histogram(position = "dodge", color = "darkblue", fill = "dodgerblue4", binwidth = 0.04) +
# theme(axis.title.x = element_blank()) + scale_x_log10() +
# labs(title = "Distibution of Iowa lakes", y = "Count")
#
# p2 <- ggplot(minnesota_lakes, aes(lake_area_ha), ) +
# geom_histogram(position = "dodge", color = "darkblue", fill = "dodgerblue4", binwidth = 0.06) +
# theme() + scale_x_log10() +
# labs(title = "Distibution of Minnesota lakes", y = "Count", x = "Lake Area (Hectares)")
# grid::grid.draw(rbind(ggplotGrob(p1), ggplotGrob(p2)))
## ^First solution before Matt told me to facet wrap.
# Facet wrap graph by state name.
p3 <- ggplot(iowa_minnesota_lakes, aes(x = lake_area_ha)) +
geom_histogram(position = "dodge", color = "darkblue", fill = "dodgerblue4", binwidth = 0.04) +
scale_x_log10() +
labs(title = "Distibution of Minnesota and Iowa lakes", y = "Count", x = "Lake Area (Hectares)") +
facet_wrap(~name, ncol = 1)
p3

4) Make an interactive plot of lakes in Iowa and Illinois and color them by lake area in hectares
# Interactive map of Iowa and Illinois
iowa_illinois_lakes %>%
arrange(-lake_area_ha) %>%
mapview(., zcol = 'lake_area_ha', alpha = 0.05, cex = 2.0)